// 封装banner轮播图相关的业务代码
import { onMounted, ref } from "vue";
import { getCategoryAPI } from "@/apis/category";
import { useRoute } from "vue-router";

export function useCategory() {
    let categoryData = ref({})
    // 获取路由传过来的id
    let route = useRoute()
    // onMounted 里面的id是给一个默认值，第一次的时候获取路由的参数
    // 后面点击导航切换路由的时候，把最新的id传过来
    let getCategory = async (id) => {
        let res = await getCategoryAPI(id)
        categoryData.value = res.result
    }
    onMounted(() => getCategory(route.params.id))

    return {
        categoryData,
        getCategory
    }
}